package com.black.cat.jvm.classfile.constantpool.impl;


import com.black.cat.jvm.classfile.ClassReader;
import com.black.cat.jvm.classfile.constantpool.BaseConstantInfo;
import com.black.cat.jvm.classfile.constantpool.ConstantInfo;
import com.black.cat.jvm.classfile.constantpool.ConstantPool;
import com.black.cat.jvm.common.CommonValue;

/**
 * @Author blackcat
 * @create 2021/8/11 20:45
 * @version: 1.0
 * @description: 类或者接口的符号引用
 * <p>
 * CONSTANT_Class_info {
 * u1 tag;
 * u2 name_index;
 * }
 */
public class ConstantInfoClass extends BaseConstantInfo implements ConstantInfo {
    private ConstantPool constantPool;
    private int nameIndex;

    public ConstantInfoClass(ConstantPool constantPool, ClassReader reader) {
        this.nameIndex = reader.nextU2ToInt();
        this.constantPool = constantPool;
    }

    @Override
    public String getValue() {
        value = constantPool.getUtfStringByIndex(nameIndex);
        return super.getValue();
    }

    @Override
    public int getTag() {
        return CommonValue.CONSTANT_POOL_TAG_CLASS;
    }
}
